package shapewar.view.tank;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import shapewar.conf.Conf;
import shapewar.engine.model.Tank;
import shapewar.engine.model.abst.Model;
import shapewar.engine.presenter.Presenter;
import shapewar.view.myview.MyView;

public class TankView extends MyView {
	int color;
	int t = 0;
	Tank tank = (Tank) getModel();
	private boolean togetherHide = false;
	public TankView(Presenter pst,Model shape) {
		super(pst,shape);
		setColor(Color.rgb((int)(Math.random()*255), (int)(Math.random()*255), (int)(Math.random()*255)));
		//paint.setMaskFilter(PaintFilter.getMaskFilter());
		//paint.setMaskFilter(PaintFilter.getLightFilter());
	}
	
	public void setColor(int color){
		this.color = color;
		paint.setColor(color);
		invalidate();
	}
	
	public int getColor(){
		return color;
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		if (!isNearFrameWindow())return;
		paint.setAlpha(255);
		//paint.setShadowLayer(0.3f, 10, 10, Color.WHITE);
		
		/*
		 * 1.0.3
		 */
		
		if(hidingCheck(paint))return;
		super.onDraw(canvas);
		
		Paint p = new Paint();
		p.setTextSize(32);
		p.setAntiAlias(true);
		p.setColor(Color.WHITE);
		canvas.drawText(tank.getUser().info.name, getRelativePos().x - p.measureText(tank.getUser().info.name)/2, getRelativePos().y+Conf.SIZE*40, p);
	}
	
	public boolean hidingCheck(Paint paint){
		if(togetherHide){
			if(tank.isPlayer())
				paint.setAlpha(50);
			else{
				if(pst.ect.player!=null){
					if(pst.ect.player.wall!=null){
						if(pst.ect.player.wall==tank.wall)
							paint.setAlpha(50);
						else 
							return true;
					}else{
						return true;
					}
				}
			}
		}
		return false;
	}
	
	public void setTogetherHide(boolean bo){
		this.togetherHide  = bo;
	}
}
